/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author admin-pc
 */
public class ConnectionFactory {
    
    String driverClassName = "oracle.jdbc.driver.OracleDriver";
    String connectionUrl = "jdbc:oracle:thin:@localhost:1521:XE";
    String dbUser = "andy";
    String dbPwd = "123";
    
    private static ConnectionFactory connectionFactory=null;
    
    private static Logger log = Logger.getLogger(ConnectionFactory.class.getName());    
    private ConnectionFactory() {
        try{
            Class.forName(driverClassName);
        }
        catch(ClassNotFoundException e){
            log.log(Level.SEVERE,"Exception: ",e);
        }
    }
    
    public Connection getConnection() throws SQLException {
        Connection conn = null;
        conn = DriverManager.getConnection(connectionUrl,dbUser,dbPwd);
        return conn;
    }
    
    public static synchronized ConnectionFactory getInstance(){
        if(connectionFactory==null){
            connectionFactory = new ConnectionFactory();
        }
        return connectionFactory;
    }
    
}
